/*
 * File Name: 		NativeImage.java
 * 
 * Copyright(c) 2011 Yunmai Co.,Ltd.
 * 
 * 		 All rights reserved.
 * 					
 */

package scan.bcr.ch;

import android.util.Log;



/**
 * @purpose: Native class for image operations
 * 
 * @author: chongxishen
 * 
 * @date: Jan. 2009
 */
public class NativeImage {
	
	private static final String TAG = "NativeImage";
	
	private static final String LIB = "imageengine";
	static {
		try {
			System.loadLibrary(LIB);
		} catch (Exception e) {
			Log.e("", "imageengine", e);
		}
	}

	// ///////////////////////////////////////////////////////
	// Constructor/Destructor

	public NativeImage() {

	}

	@Override
	public void finalize() {

	}

	/**
	 * NOTE: Use long type instead of Pointer value of the real C pointer. Type
	 * int is also OK, but Use long to be 64-bit safe.
	 * 
	 * Here just list all APIs of OCR Engine, MAYBE will write a class to wrap
	 * this class for better encapsulation and easy usage.
	 */
	// int HC_IMG_InitImage(PIEngine pIEngine, int components, int quality)
	public native int initImage(long pIEngine, int components, int quality);

	// int HC_IMG_LoadImage(PIEngine pIEngine, char *filename)
	public native int loadImage(long pIEngine, byte[] filename);

	public native int loadmemjpg(long pIEngine, byte[] pImgMem, int imgSize);

	// int HC_IMG_SaveImage(PIEngine pIEngine, char *filename)
	public native int saveImage(long pIEngine, byte[] filename);

	// int HC_IMG_FreeImage(PIEngine pIEngine)
	public native int freeImage(long pIEngine);

	// int HC_IMG_SetSaveParams(PIEngine pIEngine,
	// unsigned char *pImage, int width, int height, int components)
	public native int setSaveParams(long pIEngine, byte[] pImage, int width,
			int height, int components);

	public native int setSaveParamsEx(long pIEngine, long pImage, int width,
			int height, int components);

	// PIEngine HC_IMG_CreateEngine()
	public native long createEngine();

	// HC_IMG_CloseEngine(PIEngine pIEngine)
	public native int closeEngine(long pIEngine);

	// unsigned char * HC_IMG_GetImageData(PIEngine pIEngine)
	public native byte[] getImageData(long pIEngine); // use for get data, but

	// use

	// long parameter instead while saving
	public native long getImageDataEx(long pIEngine);

	// int HC_IMG_GetImageWidth(PIEngine pIEngine)
	public native int getImageWidth(long pIEngine);

	// int HC_IMG_GetImageHeight(PIEngine pIEngine)
	public native int getImageHeight(long pIEngine);

	// int HC_IMG_GetImageHeight(PIEngine pIEngine)
	public native int getImageComponent(long pIEngine);

	// int HC_IMG_IsGrayImage(PIEngine pIEngine)
	public native int isGrayImage(long pIEngine);

	// int HC_IMG_Scale(char *filenameSrc, char *filenameDst, int widthDst, int
	// heightDst)
	public native int scale(byte[] filenameSrc, byte[] filenameDst,
			int widthDst, int heightDst);

	// int HC_IMG_GetProperty(PIEngine pIEngine, char *filename)
	public native int getProperty(long pIEngine, byte[] filename);

	// remove the function while add the file into
	// your Java project. here is to avoid complie error
	// public static void main(String args[]) { NativeImage ie = new
	// NativeImage(); }
}